﻿using System;

namespace Gwn.Library.MvpVm.Events
{
    /// <summary>
    /// Data event arguments
    /// </summary>
    public class ProcessEventArgs : EventArgs
    {
        /// <summary>
        /// Gets or sets the type of the process.
        /// </summary>
        /// <value>The type of the process.</value>
        public Enum ProcessType { get; set; }

        /// <summary>
        /// Gets or sets the data.
        /// </summary>
        /// <value>The data.</value>
        public object Data { get; set; }

        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T GetData<T>()
        {
            return (T)Data;
        }

        /// <summary>
        /// Gets or sets the exception.
        /// </summary>
        /// <value>The exception.</value>
        public Exception Exception { get;set; }

        /// <summary>
        /// Gets a value indicating whether this instance is error.
        /// </summary>
        /// <value><c>true</c> if this instance is error; otherwise, <c>false</c>.</value>
        public bool IsError
        {
            get { return Exception != null; }
        }

        private string _friendlyMessage;

        /// <summary>
        /// Gets or sets the friendly message.
        /// </summary>
        /// <value>The friendly message.</value>
        public string FriendlyMessage
        {
            get
            {
                if(_friendlyMessage==null)
                {
                    if (IsError)
                        _friendlyMessage = Exception.Message;
                    else
                        return "";

                }
                return _friendlyMessage;
            }
            set { _friendlyMessage = value; }
        }
    }
}
